package org.jypj.dev.service.impl;


import org.jypj.dev.dao.INoticeMessageDao;
import org.jypj.dev.model.NoticeMessage;
import org.jypj.dev.service.INoticeMessageService;
import org.jypj.dev.util.Page;
import org.jypj.dev.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service("noticeMessageService")
public class NoticeMessageServiceImpl implements INoticeMessageService {

    @Resource
    private INoticeMessageDao noticeMessageDao;

    /**
    * 保存
    * 所有字段全都保存
    * @param noticeMessage
    * @return 保存后的对象包括ID
    */
    public int saveNoticeMessage(NoticeMessage noticeMessage){
        if(StringUtil.isEmpty(noticeMessage.getId())){
            String uuid =UUID.randomUUID().toString().replace("-", "").trim();
            noticeMessage.setId(uuid);
        }
        return noticeMessageDao.saveNoticeMessage(noticeMessage);
    }

    /**
    * 根据ID删除
    * @param id 主键ID
    * @return 删除记录数
    */
    public int deleteNoticeMessageById(String id){

        return noticeMessageDao.deleteNoticeMessageById(id);
    }

    /**
    * 根据对象删除
    * @param noticeMessage
    * @return
    */
    public int deleteNoticeMessageByObject(NoticeMessage noticeMessage){

        return noticeMessageDao.deleteNoticeMessageByObject(noticeMessage);
    }

    /**
    * 更新
    * 更新所有字段
    * @param noticeMessage
    * @return 保存后的对象包括ID
    */
    public int updateNoticeMessage(NoticeMessage noticeMessage){

        return noticeMessageDao.updateNoticeMessage(noticeMessage);
    }

    /**
    * 按ID查询
    * @parm id 主键ID
    * @return NoticeMessage
    */
    public NoticeMessage selectNoticeMessageById(String id){

        return noticeMessageDao.selectNoticeMessageById(id);
    }

    /**
    * 分页查询 包含条件
    * @param page 分页对象
    * @param map  查询条件
    * @return  List<NoticeMessage>
    */
    public Page selectOnePageByMap(Page page,Map<String,Object> map){
        List<NoticeMessage> noticeMessages =noticeMessageDao.selectOnePageByMap(page,map);
        if(noticeMessages!=null&&noticeMessages.size()>0){
            page.setResult(noticeMessages);
        }else{
            page.setResult(new ArrayList<NoticeMessage>());
        }
        return page;
    }
    /**
    * 分页查询 包含对象条件
    * @param page 分页对象
    * @param noticeMessage  查询条件
    * @return Page
    */
    public Page selectOnePageByNoticeMessage(Page page,NoticeMessage noticeMessage){
        List<NoticeMessage> noticeMessages =noticeMessageDao.selectOnePageByNoticeMessage(page,noticeMessage);
        if(noticeMessages!=null&&noticeMessages.size()>0){
            page.setResult(noticeMessages);
        }else{
            page.setResult(new ArrayList<NoticeMessage>());
        }
        return page;
    }

    /**
    * 按条件查询全部的
    * @param map  查询条件
    * @return  List<NoticeMessage>
    */
    public List<NoticeMessage> selectAllByMap(Map<String,Object> map){
        return noticeMessageDao.selectAllByMap(map);
    }


    /**
    * 按条件查询全部的
    * @param noticeMessage  查询条件
    * @return  List<NoticeMessage>
    */
    public List<NoticeMessage> selectAllByNoticeMessage(NoticeMessage noticeMessage){

        return noticeMessageDao.selectAllByNoticeMessage(noticeMessage);
    }

    /**
    * 按条件查询单个对象
    * @param map  查询条件
    * @return  NoticeMessage
    */
    public NoticeMessage selectObjectByMap(Map<String,Object> map){

        return noticeMessageDao.selectObjectByMap(map);
    }

    /**
    * 按条件查询单个对象
    * @param noticeMessage  查询条件
    * @return  NoticeMessage
    */
    public NoticeMessage selectObjectByNoticeMessage(NoticeMessage noticeMessage){

        return noticeMessageDao.selectObjectByNoticeMessage(noticeMessage);
    }
}